﻿using System;

namespace IOP.Pulsar.Abstractions
{
    /// <summary>
    /// 管线建设者接口
    /// </summary>
    /// <typeparam name="TContext"></typeparam>
    public interface IProductLineBuilder<TContext>
        where TContext : class
    {

        /// <summary>
        /// 构建委托链
        /// </summary>
        /// <returns></returns>
        ProductLineDelegate<TContext> Build();

        /// <summary>
        /// 清除所有中间件
        /// </summary>
        void Clear();

        /// <summary>
        /// 添加管线中间件
        /// </summary>
        /// <param name="middleware"></param>
        /// <returns></returns>
        IProductLineBuilder<TContext> Use(Func<ProductLineDelegate<TContext>, ProductLineDelegate<TContext>> middleware);

        /// <summary>
        /// 短路中间件
        /// </summary>
        /// <param name="endPoint"></param>
        /// <returns></returns>
        IProductLineBuilder<TContext> Run(ProductLineDelegate<TContext> endPoint);

        /// <summary>
        /// 添加中间件
        /// </summary>
        /// <typeparam name="TMiddleware"></typeparam>
        /// <returns></returns>
        IProductLineBuilder<TContext> UseMiddleware<TMiddleware>()
            where TMiddleware : class, IProductLineMiddleware<TContext>;
    }
}
